package com.detroitchow;

import java.util.ArrayList;

import com.detroitchow.R;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class StoresArrayAdapter extends ArrayAdapter<StoreVO> implements OnTouchListener {

  private final Activity myContext;
  private final ArrayList<StoreVO> stores;
  private TextView txtWeb;
  private TextView txtName;
  private TextView txtAddress;
  private TextView txtLocation;
  private TextView txtPhone;
  
  public StoresArrayAdapter(Activity context, int textViewResourceId, int elementId, ArrayList<StoreVO> stores) {
    super(context, textViewResourceId, elementId, stores);
    this.myContext = context;
    this.stores = stores;
  }
  
 
  public View getView(int index, View convertView, ViewGroup parent){
    
    StoreVO store = this.stores.get(index);
    View row = convertView;
    if(row==null){
      LayoutInflater inflater = myContext.getLayoutInflater();
      row = inflater.inflate( R.layout.directoryitem, parent, false);
    }
    
    txtName = (TextView) row.findViewById(R.id.txtstoretitle);
    txtName.setText(store.name);
    
    txtAddress = (TextView) row.findViewById(R.id.txtaddress);
    txtAddress.setText(store.address);
    
    txtLocation= (TextView) row.findViewById(R.id.txtlocation);
    txtLocation.setText(store.city + " " + store.state + " " + store.zip);
    
    txtPhone = (TextView) row.findViewById(R.id.txtphone);
    txtPhone.setText(DetroitChowUtils.formattedPhoneNumber(store.phone));
    txtPhone.setOnTouchListener(this);
    
    txtWeb = (TextView) row.findViewById(R.id.txtweb);
    if(store.website != null && store.website.length() > 0) 
      txtWeb.setText(store.website.replaceAll("^http://",""));
    else
      txtWeb.setText("");
    return row;
  }


	public boolean onTouch(View v, MotionEvent event) {
	  // TODO Auto-generated method stub
		LogUtil.log("StoresArrayAdaptrer rtonTouch", "Testing 123");
		
	  return false;
  }
 }
